﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Markup;

namespace SDF
{
    [ContentProperty("Cells")]
    public class TableRow: SmartTextElement, IValidateParent
    {
        #region Constructor

        public TableRow()
        {
            Cells = new TableCellCollection(this);
        }

        #endregion

        #region DependencyProperty

        public static readonly DependencyProperty HeightProperty = DependencyProperty.Register(
            "Height",
            typeof(double),
            typeof(TableRow),
            new FrameworkPropertyMetadata(double.NaN, FrameworkPropertyMetadataOptions.AffectsMeasure, SmartTextElement.OnMeasureAffected),
            new ValidateValueCallback(ValidateHeight));

        private static bool ValidateHeight(object value)
        {
            var height = (double)value;
            if (double.IsInfinity(height))
                return false;

            if (height < 0)
                return false;

            return true;
        }

        #endregion

        #region Properties

        public TableCellCollection Cells { get; private set; }

        public double Height
        {
            get { return (double)GetValue(HeightProperty); }
            set { SetValue(HeightProperty, value); }
        }

        #endregion

        #region IsVisualProperty Method

        protected override bool IsVisualProperty(string propertyName)
        {
            switch (propertyName)
            {
                case "Background":
                case "Height":
                    return true;

                default:
                    return false;
            }
        }

        #endregion

        #region IValidateParent Implementation

        public bool IsValidParent(DependencyObject parent)
        {
            return parent is Table;
        }

        #endregion

    }
}
